const formatTime = (date,type=1) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  if (type == 1){
    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  } else if (type == 2){
    return [year, month, day].map(formatNumber).join('-')
  }
  
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const baseFn = {
  notNull:function(){

  },
  isFn: function (fn) {
    return !!fn && !fn.nodename && fn.constructor != String && fn.constructor != RegExp && fn.constructor != Array && /function/i.test(fn + "")
  },
  deepcopy: function (obj) {
    //多维数组深拷贝
    var out = [], i = 0, len = obj.length;
    for (; i < len; i++) {
      if (obj[i] instanceof Array) {
        out[i] = deepcopy(obj[i]);
      }
      else out[i] = obj[i];
    }
    return out;
  },
  objDeepCopy: function (source) {
    //数组对象深拷贝
    var sourceCopy = source instanceof Array ? [] : {};
    for (var item in source) {
      sourceCopy[item] = typeof source[item] === 'object' ? this.objDeepCopy(source[item]) : source[item];
    }
    return sourceCopy;
  },
  objDelElm: function (obj, array) {
    for (var i in obj) {
      if (array) {
        if (!(Object.prototype.toString.call(array) == '[object Array]')) {
          array = [array]
        }
        if (array.some(function (val) {
          return val == i
        })) {
          continue;
        }
      }
      delete obj[i]
    }
  },
  isArray: function (o) {
    return Object.prototype.toString.call(o) == '[object Array]';
  },
  notNull: function (strings, kus) {
    var _kus = ''
    if (arguments[1]) {
      _kus = null
    }
    if (strings != null && strings != undefined && strings !== _kus) {
      return true
    } else {
      return false
    }
  },
  notNull2: function (strings, rd, kus) {
    var _kus = ''
    if (arguments[2]) {
      _kus = null
    }
    if (strings != null && strings != undefined && strings !== _kus) {
      if (arguments[1]) {
        return strings
      } else {
        return true
      }
    } else {
      if (arguments[1] && arguments[2]) {
        return arguments[2]
      } else {
        return false
      }

    }
  }
}
module.exports = {
  formatTime: formatTime,
  baseFn: baseFn
}
